<?php

namespace App\Admin\Controllers\Dedusting;

use App\Models\DedustingFeedback;
use App\Http\Controllers\Controller;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Widgets\Callout;
use Illuminate\Support\Facades\DB;
use Dcat\Admin\Form;
use Dcat\Admin\Admin;
use Dcat\Admin\Show;
use Illuminate\Http\Request;
use App\Handlers\IotCardHandler;

class FeedbackController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->header('反馈列表')
            ->description('')
            ->body($this->grid());
    }

    protected function grid()
    {
        return new Grid(DedustingFeedback::with(['poster']), function (Grid $grid) {
            $grid->column('poster.mobile', '反馈者');
            $grid->column('detail', '详情');
            $grid->column('status', '状态')->using(DedustingFeedback::STATUS_TEXT);
            $grid->column('created_at', '创建时间');
            $grid->column('updated_at', '修改时间');

            $grid->disableCreateButton();
        });
    }

    public function show($id, Content $content)
    {
        return $content->header('反馈')
            ->description('详情')
            ->body(Show::make($id, DedustingFeedback::with(['poster']), function (Show $show) {
                $show->field('poster.mobile', '反馈者');
                $show->field('detail', '详情');
                $show->field('image', '问题现象图片')->image();
                $show->field('video', '问题现象视频')->video();  //自己加的，改基库

                $show->field('status', '状态')->using(DedustingFeedback::STATUS_TEXT);

                $show->field('created_at', '创建时间');
                $show->field('updated_at', '修改时间');
            }));
    }

    public function update($id){
        return $this->form()->update($id);
    }
    
    public function form(){
        return Form::make(new DedustingFeedback(), function (Form $form) {
            $form->radio('status', '状态')->options(DedustingFeedback::STATUS_TEXT)->required();
            $form->hidden('operator')->value(Admin::user()->id);

            $form->saving(function (Form $form) {
                $form->operator = Admin::user()->id;
            });
        });
    }

    public function edit($id,Content $content){
        return $content
            ->title('文库编辑')
            ->description('编辑')
            ->body($this->form()->edit($id));
    }

    public function destroy($id)
    {
        return $this->form()->destroy($id);
    }
}